Let's get a list of all of our MPs first


In [1]:
import requests
import json

#Dewan Rakyat MP Posts in Sinar Malaysia Popit Database

dewan_rakyat_request = requests.get('https://sinar-malaysia.popit.mysociety.org/api/v0.1/organizations/53633b5a19ee29270d8a9ecf')

posts = json.loads(dewan_rakyat_request.content)['result']['memberships']

Now we will load up information on the MPs holding these posts


In [2]:
MP_ids = []

#Current MPs should not have any end dates
for member in posts:
    #db not always clean, making sure either no end_date or empty value
    
    if member.has_key('end_date'):
        if member['end_date'] == '':
            MP_ids.append(member['person_id'])
            
    if not member.has_key('end_date'):
        MP_ids.append(member['person_id'])
        
#There are some bad data during automated import from GE13 results.
#This will be cleaned up in a few weeks, but we check for duplicates just in case.
#There should only ever be 1 person holding 1 post at a moment in time.

def uniq(seq):
    #http://www.peterbe.com/plog/uniqifiers-benchmark
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if not (x in seen or seen_add(x))]

def person(person_id):
    #Load up information of persons from Popit database
    req = requests.get('https://sinar-malaysia.popit.mysociety.org/api/v0.1/persons/' + person_id)
    return json.loads(req.content)['result']

MP_ids = uniq(MP_ids)

#Pull down the data of current MPs from Popit Database
MP_Twitter = []
MP_Facebook = []

for id in MP_ids:
    person_data = person(id)
    if person_data.has_key('contact_details'):
        for contact in person_data['contact_details']:
            if contact['type']=='twitter':
                MP_Twitter.append((person_data['name'],contact['value']))
            if contact['type']=='facebook':
                MP_Facebook.append((person_data['name'],contact['value']))

In [4]:
MP_Twitter


Out[4]:
[(u'Wong Chen', u'WongChenPKR'),
 (u'Ong Kian Ming', u'imokman'),
 (u'Tengku Adnan Tengku Mansor', u'tengkuadnanreal'),
 (u'Liew Chin Tong', u'LiewChinTong'),
 (u'Abdul Hadi Bin Awang', u'abdulhadiawang'),
 (u'Tan Seng Giaw', u'senggiaw'),
 (u'Tan Kee Kwong', u'tankeekwong'),
 (u'Aziz Kaprawi', u'akaprawi'),
 (u'Hishammuddin Hussein', u'HishammuddinH2O'),
 (u'Ahmad Maslan', u'ahmadmaslan'),
 (u'Maximus Ongkili', u'mpkotamarudu'),
 (u'Rosnah Abdul Rashid Shirlin', u'Rosnah_ARS'),
 (u'Ewon Ebin', u'EwonEbin'),
 (u'Mohd Shafie Apdal', u'mohdshafieapdal'),
 (u'Che Rosli Bin Che Mat', u'drcherosli'),
 (u'Nancy Shukri', u'nancyshukri'),
 (u'Joseph Salang Gandum', u'joseph_salang'),
 (u'Tengku Razaleigh Hamzah', u'razaleigh'),
 (u'Sim Chee Keong', u'scheekeong'),
 (u'Kasthuriraani Patto', u'kasthuripatto'),
 (u'Zairil Khir Johari', u'zairilkj'),
 (u'Najib Tun Razak', u'najibrazak'),
 (u'Gobind Singh Deo', u'GobindSinghDeo'),
 (u'Khalid Abdul Samad', u'khalidsamad'),
 (u'Sivarasa Rasiah', u'SivarasaRasiah'),
 (u'Abdul Khalid Ibrahim', u'khalid_ibrahim'),
 (u'Mohamed Hanipa Maidin', u'hanipamaidin'),
 (u'Chua Tian Chang', u'tianchua'),
 (u'Lim Lip Eng', u'limlipeng'),
 (u'Johari Abdul Ghani', u'joharighani_ttw'),
 (u'Nurul Izzah Anwar', u'n_izzah'),
 (u'Teresa Kok Suh Sim', u'teresakok'),
 (u'Loke Siew Fook', u'anthonyloke'),
 (u'Hasan Malek', u'datohasanmalek'),
 (u'Teo Kok Seong', u'teokokseong'),
 (u'Khairy Jamaluddin Abu Bakar', u'Khairykj'),
 (u'Shaziman Abu Mansor', u'shazimanmansor'),
 (u'Mas Ermieyati Samsudin', u'emysamsudin'),
 (u'Abu Bakar Mohamad Diah', u'DatukDrAbuBakar'),
 (u'Shamsul Iskandar Mohd Akin', u'shamsuliskandar'),
 (u'Subramaniam K.V. Sathasivam', u'kvssubra'),
 (u'Anuar Abdul Manap', u'pm_anuar'),
 (u'Chua Tee Yong', u'chuaty'),
 (u'Muhyiddin Yassin', u'muhyiddinyassin'),
 (u'Hamim Samuri', u'hamimsamuri'),
 (u'Er Teck Hwa', u'erteckhwa'),
 (u'Razali Ibrahim', u'razaliibrahim'),
 (u'Wee Ka Siong', u'weekasiongmp'),
 (u'Khoo Soo Seang', u'khoosooseang'),
 (u'Normala Abdul Samad', u'normalasamad'),
 (u'Lim Kit Siang', u'limkitsiang'),
 (u'Teo Nie Ching', u'teonieching'),
 (u'Idris Jusoh', u'idrisjusoh'),
 (u'Wong Sze Phin', u'jimmyspw'),
 (u'Madius Tangau', u'mtangau'),
 (u'Jumat Idris', u'datukjumat'),
 (u'Abdul Rahman Dahlan', u'mpkotabelud'),
 (u'Anifah Aman', u'anifah_aman'),
 (u'Azizah Mohd Dun', u'azizahmohddun'),
 (u'Ronald Kiandee', u'rkiandee'),
 (u'Bung Mokhtar Radin', u'mykinabatangan'),
 (u'Yap Kain Ching', u'maryyapkc'),
 (u'Wan Junaidi Tuanku Jaafar', u'drwan_junaidi'),
 (u'Fadillah Yusof', u'petrajayamp'),
 (u'Nawawi Ahmad', u'nawawikawi'),
 (u'Hee Loy Sian', u'heeloysian'),
 (u'Tony Pua Kiam Wee', u'tonypua'),
 (u'Julian Tan Kok Ping', u'Juliantkp'),
 (u'Rohani Abdul Karim', u'hjhrohanikarim'),
 (u'Douglas Uggah Embas', u'uggahembas'),
 (u'Alice Lau Kiong Yieng', u'alicelky'),
 (u'Oscar Ling Chai Yew', u'oscar_ling'),
 (u'Joseph Entulu Belaun', u'josephEB_myg'),
 (u'N Surendran A/L K Nagarajan', u'nsurendrann')]

In [5]:
MP_Facebook


Out[5]:
[(u'Wong Chen', u'wongchenpkr'),
 (u'Ong Kian Ming', u'ongkianming'),
 (u'Tan Kok Wai', u'mptankokwai'),
 (u'Tengku Adnan Tengku Mansor', u'officialkunan'),
 (u'Liew Chin Tong', u'liewchintong.my'),
 (u'Abdul Hadi Bin Awang', u'abdulhadiawang'),
 (u'Tan Seng Giaw', u'Tan-Seng-Giaw-\u9648\u80dc\u5c27/188578847839319'),
 (u'Tan Kee Kwong', u'Tankeekwong'),
 (u'Ahmad Fauzi Zahari', u'DatoAhmadFauziZahari'),
 (u'Mohamed Isa Abdul Samad', u'isasamad'),
 (u'Sim Tong Him', u'SimTongHimchenTongQin'),
 (u'Aziz Kaprawi', u'pages/Aziz-Kaprawi/708746809179782'),
 (u'Hishammuddin Hussein', u'HishammuddinH2O'),
 (u'Noor Ehsanuddin Mohd Harun Narrashid', u'MesraKotaTinggi'),
 (u'Ahmad Maslan', u'ahmadmaslan'),
 (u'Rosnah Abdul Rashid Shirlin',
  u'pages/Rosnah-Abdul-Rashid-Shirlin/125957797477479'),
 (u'Ewon Ebin', u'pages/Datuk-Dr-Ewon-Ebin/1424134421136752'),
 (u'Mohd Shafie Apdal', u'pages/Shafie-Apdal-Official/455014837852949'),
 (u'Che Rosli Bin Che Mat', u'YBdrCheRosli'),
 (u'Nancy Shukri', u'hajahnancyshukri'),
 (u'William Mawan Ikom', u'pages/Tan-Sri-William-Mawan-Ikom/274287065936919'),
 (u'Joseph Salang Gandum', u'pages/Joseph-Salang-Gandum/111340798941983'),
 (u'Johari Abdul', u'johari.b.abdul'),
 (u'Tengku Razaleigh Hamzah', u'tengku.razaleighhamzah'),
 (u'Tiong King Sing',
  u'pages/Datuk-Seri-Tiong-King-Sing-\u62ff\u7763\u65af\u91cc\u5f20\u5e86\u4fe1/904596852885487'),
 (u'Ahmad Lai Bujang', u'pages/Haji-Ahmad-Lai-Bin-Bujang/108765849247814'),
 (u'Sim Chee Keong', u'StevenSimCK'),
 (u'Kasthuriraani Patto', u'kasthuripatto'),
 (u'Zairil Khir Johari', u'ZairilKJ'),
 (u'Najib Tun Razak', u'najibrazak'),
 (u'Gobind Singh Deo', u'gobindsinghdeo'),
 (u'Khalid Abdul Samad', u'khalidsamad'),
 (u'Nik Mohamad Abduh Bin Nik Abdul Aziz', u'nik.abduh'),
 (u'Yap Pian Hon', u'yappianhon'),
 (u'Sivarasa Rasiah', u'ybsivarasa'),
 (u'Abdul Khalid Ibrahim', u'Abdul-Khalid-Ibrahim/38012338900'),
 (u'Chua Tian Chang', u'chuatianchang'),
 (u'Lim Lip Eng', u'limlipengOfficialPage'),
 (u'Johari Abdul Ghani', u'JohariTitiwangsa'),
 (u'Nurul Izzah Anwar', u'nurulizzahanwar'),
 (u'Teresa Kok Suh Sim', u'TeresaKokSuhSim'),
 (u'Zainudin Ismail', u'YB-Hj-Zainudin-Hj-Ismail-P126-Jelebu/696882973720214'),
 (u'Loke Siew Fook', u'Anthony-Loke-Siew-Fook/129323924541?fref=nf'),
 (u'Hasan Malek', u'YB.Dato.Sri.Hasan.Malek'),
 (u'Teo Kok Seong', u'teokokseong'),
 (u'Khairy Jamaluddin Abu Bakar', u'Khairykj'),
 (u'Shaziman Abu Mansor', u'pages/Shaziman-Bin-Abu-Mansor/192745604082313'),
 (u'Mas Ermieyati Samsudin', u'masermieyatisamsudin'),
 (u'Koh Nai Kwong', u'pages/KOH-NAI-KWONG/1422280121336238'),
 (u'Abu Bakar Mohamad Diah', u'DatukProfAbuBakar'),
 (u'Shamsul Iskandar Mohd Akin', u'ShamsulIskandarMohdAkin'),
 (u'Ahmad Hamzah', u'pages/YB-Datuk-Wira-Hj-Ahmad-bin-Hamzah/141510279275219'),
 (u'Subramaniam K.V. Sathasivam', u'Dr.S.Subramaniam'),
 (u'Anuar Abdul Manap', u'anuarmanapsekijang'),
 (u'Chua Tee Yong', u'ChuaTeeYong'),
 (u'Muhyiddin Yassin', u'pages/Muhyiddin-Yassin/112183975526837'),
 (u'Hamim Samuri', u'HamimLedang'),
 (u'Er Teck Hwa', u'erteckhwa'),
 (u'Razali Ibrahim', u'dato.r.ibrahim'),
 (u'Noraini Ahmad', u'ParlimenParitSulongdatonoraini'),
 (u'Wee Ka Siong', u'weekasiong'),
 (u'Mohd Idris Jusi', u'IdrisJusi'),
 (u'Abdul Latiff Ahmad', u'DrAbdulLatiffAhmad'),
 (u'Halimah Mohamed Sadique', u'tenggafap155'),
 (u'Azalina Othman Said', u'pages/Azalina-Othman/36136457050'),
 (u'Khoo Soo Seang', u'khoosooseang'),
 (u'Lim Kit Siang', u'limkitsiang'),
 (u'Teo Nie Ching', u'TeoNieChing'),
 (u'Wee Jeck Seng', u'weejeckseng'),
 (u'Idris Jusoh', u'datoseriidrisjusoh'),
 (u'Madius Tangau', u'Madiustangau'),
 (u'Jumat Idris', u'jumat.idris.3'),
 (u'Abdul Rahman Dahlan', u'rahmandahlan.my'),
 (u'Ignatius Dorell Leiking', u'MP.Penampang'),
 (u'Anifah Aman', u'anifahaman2'),
 (u'Azizah Mohd Dun', u'pages/Azizah-Dun/108644619201398'),
 (u'Joseph Kurup', u'pages/Joseph-Kurup/110676225677185'),
 (u'Bung Mokhtar Radin', u'pages/Bung-Mokhtar-Radin/212518438770582'),
 (u'Yap Kain Ching', u'maryykc'),
 (u'Nogeh Anak Gumbek',
  u'pages/YB-Tuan-Anthony-Nogeh-Gumbek/1541953612750393'),
 (u'Wan Junaidi Tuanku Jaafar',
  u'pages/Drhaji-Wan-Junaidi-Tuanku-Jaafar/346539785449311'),
 (u'Fadillah Yusof', u'fadillah.yusof'),
 (u'Chong Chieng Jen', u'ChongChiengJen'),
 (u'Nawawi Ahmad', u'nawikawifb'),
 (u'Hee Loy Sian', u'HeeLoySian'),
 (u'Tony Pua Kiam Wee', u'MPTonyPua'),
 (u'Julian Tan Kok Ping', u'JulianTanKokPing'),
 (u'Rubiah Wang', u'pages/P197-Kota-Samarahan/560456373976758'),
 (u'James Dawos Mamit', u'pages/James-Dawos-Mamit/178296152214842'),
 (u'Richard Riot Jaem', u'pages/Richard-Riot-Jaem/148954378497570'),
 (u'Rohani Abdul Karim', u'pages/Rohani-Abdul-Karim/336467416395357'),
 (u'Masir Kujat', u'pages/YB-Masir-Kujat/235333126676906'),
 (u'Douglas Uggah Embas', u'pages/Douglas-Uggah-Embas/167428696649138'),
 (u'Wong Ling Biu', u'lingbiu.andrewwong'),
 (u'Norah Abdul Rahman', u'people/Datuk-Norah-Abd-Rahman/100009456243105'),
 (u'Alice Lau Kiong Yieng', u'pages/Alice-Lau-Kiong-Yieng/216228058403393'),
 (u'Oscar Ling Chai Yew', u'oscar.ling.16'),
 (u'Joseph Entulu Belaun', u'JosephEntulu'),
 (u'Alexander Nanta Linggi', u'pages/Alexander-Nanta-Linggi/158394677663381'),
 (u'N Surendran A/L K Nagarajan', u'N.SurendranPKR')]

In [6]:
len(MP_Facebook)


Out[6]:
100

In [ ]: